#include <iostream>
#include "comm.hpp"
#include <unistd.h>

int main()
{
    char buffer[1024];
    set_non_block(0); // 将0设置为非阻塞
    while (true)
    {
        ssize_t n = ::read(0, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            buffer[n] = 0;
            std::cout << "echo :" << buffer << std::endl;
        }
        else
        {
            if (errno == EWOULDBLOCK || errno == EAGAIN)
            {
                std::cout << "底层数据没有就绪，下次在试试！做其他事情。" << std::endl;
                sleep(1);
                continue;
            }
            else if (errno == EINTR)
            {
                continue;
            }
            else
            {
                std::cout << "读取错误.... s: " << n << "errno :" << errno << std::endl;
                sleep(1);
            }
        }
    }
    return 0;
}